﻿@model SLSYJ.Controllers.Models.EmployeeViewModel
@using SLSYJ.Controllers.Helpers
@using Microsoft.Web.Helpers
@using SLSYJ.Controllers.DTOs
@using System.Configuration

@{
    ViewBag.Title = "Crear";
}
<script src="@Url.Content("~/Scripts/grid.locale-es.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.jqGrid.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/fileuploader.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Validations.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/Common.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/themes/ui.jqgrid.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/themes/base/jquery.ui.dialog.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/themes/base/fileuploader.css")" rel="stylesheet" type="text/css" />

<script type="text/javascript">
    var URLBase = @Html.Raw(Json.Encode(ConfigurationManager.AppSettings["baseURL"]));
    $(document).ready(function () {
        var uploader = new qq.FileUploader({
            element: document.getElementById('fileuploader'),
            action: URLBase + '/Employees/UploadEmployeeImage',
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            onSubmit: function (id, fileName) {
                $('.qq-upload-list').hide();

                var fileDescription = $('#fileDescriptionSelectList').val()
                if (fileDescription == 'Other')
                    fileDescription = $('#fileDescriptionOther').val();

                uploader.setParams({
                    fileDescription: fileName
                });
            },
            onComplete: function (id, fileName, responseJSON) {
                var BaseUrl = 'http://' + top.location.host;
                $('.qq-upload-list').hide();
                $('#DTO_Picture').attr("src", BaseUrl + responseJSON.fileName);
            }
        });
        $("#tabs").tabs();
        $('#category').change(function () {
            $("#loading").show();
            var BaseUrl = 'http://' + top.location.host + URLBase;
            var id = $(this).val();
            $.ajax({
                url: BaseUrl + '/Categories/UpdateCategorySalary/',
                type: "POST",
                data: { "categoryId": id }
            })
                .success(function (responseJSON) {
                    $("#loading").hide();
                    $("#DTO_Category_CategoryEmployee_GrossSalary").val(responseJSON);
                })
                .error(function (xhr, status) {
                    alert(xhr.responseText);
                });
            });
        var id = $('#category').val();
        jQuery("#list").jqGrid({
            url: URLBase + '/Categories/GetTaskList/',
            postData: { categoryId: id },
            datatype: 'json',
            mtype: 'GET',
            colNames: ['Descripción'],
            colModel: [{ name: 'Name', index: 'Name', width: 275, align: 'left', editable: false}],
            pager: '#pager',
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'Descripcion',
            sortorder: 'desc',
            gridview: true,
            shrinkToFit: false,
            autowidth: true,
            caption: 'Tareas',
            multiselect: true
        });
        $("#list").navGrid("#pager", { edit: false, add: false, del: false });
    });
</script>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <div class="line"></div>
         
    <article id="article1">
        <h2>Crear nuevo empleado</h2>
                    
        <div class="line"></div>
                    
        <div class="articleBody clear">
            <table style="width: 100%;border:0;">
            <tr>
                <td>
                    <fieldset>
                        <legend>Datos personales</legend>
                        <table style="width: 100%;border:0;">
                            <tr>
                                <td>
                                    <table style="width: 100%;border:0;">
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.Name)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.EditorFor(model => model.DTO.Name)
                                                    @Html.ValidationMessageFor(model => model.DTO.Name)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.Surname)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.EditorFor(model => model.DTO.Surname)
                                                    @Html.ValidationMessageFor(model => model.DTO.Surname)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.DNInumber)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.EditorFor(model => model.DTO.DNInumber)
                                                    @Html.ValidationMessageFor(model => model.DTO.DNInumber)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.CUILnumber)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.EditorFor(model => model.DTO.CUILnumber)
                                                    @Html.ValidationMessageFor(model => model.DTO.CUILnumber)
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td>
                                    <table>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.Sex)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.RadioButtonForEnum(x => x.DTO.Sex)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.DateOfBirth)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.TextBox("DTO.DateOfBirth", Model.DTO.DateOfBirth.ToShortDateString(), new { @class = "date" })
                                                    @Html.ValidationMessageFor(model => model.DTO.DateOfBirth)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.MaritalStatus)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.RadioButtonForEnum(x => x.DTO.MaritalStatus)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    Foto:
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    <!--<img src="@(String.IsNullOrEmpty(Model.DTO.Picture) ? @Url.Content("~/Content/themes/base/images/facebook-no-image1.gif") : Model.DTO.Picture)" id="profileImage" alt='' width='150px' height='150px'/><br/>-->
                                                    @Html.ImageFor(Model.DTO.Picture)
                                                    <div id="fileuploader">
                                                        <noscript>
                                                            @using (Html.BeginForm("Upload", "Employees", FormMethod.Post, new { enctype = "multipart/form-data" }))
                                                            {
                                                                <input type="file" name="photo" id="photo" />   
                                                                <input type="submit" value="Upload" name="submit"/>
                                                            }
                                                        </noscript>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </fieldset>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="line"></div>
                </td>
            </tr>
            <tr>
                <td>
                    <fieldset>
                        <legend>Datos laborales</legend>
                        <table style="width: 100%;border:0;">
                            <tr>
                                <td>
                                    <table style="width: 100%;border:0;">
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.FileNumber)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.EditorFor(model => model.DTO.FileNumber)
                                                    @Html.ValidationMessageFor(model => model.DTO.FileNumber)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.CardNumber)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.EditorFor(model => model.DTO.CardNumber)
                                                    @Html.ValidationMessageFor(model => model.DTO.CardNumber)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.HiringDate)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.TextBox("DTO.HiringDate", Model.DTO.HiringDate.ToShortDateString(), new { @class = "date" })
                                                    @Html.ValidationMessageFor(model => model.DTO.HiringDate)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.Comments)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.TextAreaFor(model => model.DTO.Comments, new { width = 500 })
                                                    @Html.ValidationMessageFor(model => model.DTO.Comments)
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td>
                                    <table style="width: 100%;border:0;">
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.Salary)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.TextBox("DTO.Salary", Model.DTO.Salary, new { @class = "money" })
                                                    @Html.ValidationMessageFor(model => model.DTO.Salary)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.RemunerativeSalary)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.TextBox("DTO.RemunerativeSalary", Model.DTO.RemunerativeSalary, new { @class = "money" })
                                                    @Html.ValidationMessageFor(model => model.DTO.RemunerativeSalary)
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.NonRemunerativeSalary)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">

                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <div class="editor-label">
                                                    @Html.LabelFor(model => model.DTO.HasAgreement)
                                                </div>
                                            </td>
                                            <td>
                                                <div class="editor-field">
                                                    @Html.EditorFor(model => model.DTO.HasAgreement)
                                                    @Html.ValidationMessageFor(model => model.DTO.HasAgreement)
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <div class="line"></div>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <div id="tabs" style="with:100%;">
                                        <ul>
                                            <li><a href="#tabs-1">@Html.LabelFor(model => model.DTO.EmployeeBank)</a></li>
                                            <li><a href="#tabs-2">@Html.LabelFor(model => model.DTO.CateorySector)</a></li>
                                            <li><a href="#tabs-3">@Html.LabelFor(model => model.DTO.Category)</a></li>
                                        </ul>
                                        <div id="tabs-1">
                                            <table>
                                                <tr>
                                                    <td>
                                                        <div class="editor-label">
                                                            @Html.LabelFor(model => model.DTO.EmployeeBank.Name)
                                                            @Html.EditorFor(model => model.DTO.EmployeeBank.Name)
                                                            @Html.ValidationMessageFor(model => model.DTO.EmployeeBank.Name)
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="editor-label">
                                                            @Html.LabelFor(model => model.DTO.EmployeeBank.AccountNumber)
                                                            @Html.EditorFor(model => model.DTO.EmployeeBank.AccountNumber)
                                                            @Html.ValidationMessageFor(model => model.DTO.EmployeeBank.AccountNumber)
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="editor-label">
                                                            @Html.LabelFor(model => model.DTO.EmployeeBank.CBUNumber)
                                                            @Html.EditorFor(model => model.DTO.EmployeeBank.CBUNumber)
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                        <div id="tabs-2">
                                            <table>
                                                <tr>
                                                    <td>
                                                        <div class="editor-label">
                                                            @Html.LabelFor(model => model.DTO.SectorBranch)
                                                            @Html.DropdownForEnum(Model.DTO.SectorBranch, "– Seleccionar sucursal –", "DTO.SectorBranch")
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="editor-label">
                                                            @Html.LabelFor(model => model.DTO.CateorySector)
                                                            @Html.DropDownListFor(model => model.DTO.CateorySector.ID, new SelectList(Model.Sectores, "ID", "Name"), "– Seleccionar sector –")
                                                        </div>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                        <div id="tabs-3">
                                            <table>
                                                <tr>
                                                    <td>
                                                        <div class="editor-label">
                                                            @Html.LabelFor(model => model.DTO.Category.CategoryEmployee)
                                                            @Html.DropDownListFor(model => model.DTO.Category.CategoryEmployee.ID, new SelectList(Model.Categories, "ID", "Name"), "– Seleccionar categoria –", new { @Id = "category" })
                                                            @Html.ValidationMessageFor(model => model.DTO.Category.CategoryEmployee.Name)
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="editor-label">
                                                            @Html.LabelFor(model => model.DTO.Category.CategoryEmployee.GrossSalary)
                                                            @Html.TextBox("DTO.Category.CategoryEmployee.GrossSalary", Model.DTO.Category.CategoryEmployee.GrossSalary, new { @class = "money" })
                                                            @Html.ValidationMessageFor(model => model.DTO.Category.CategoryEmployee.GrossSalary)
                                                        </div>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <table>
                                                            <tr>
                                                                <td>&nbsp;</td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    @Html.LabelFor(model => model.DTO.Category.CategoryEmployee.CategoryTasks)
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <table id="list" class="scroll" cellpadding="0" cellspacing="0"></table>
                                                                <div id="pager" class="scroll" style="text-align:center;"></div>
                                                                <p>
                                                                </p>
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </fieldset>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="line"></div>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="submit" value="Crear" /> | @Html.ActionLink("Volver a la lista", "List")
                </td>
            </tr>
    </table>
        </div>
    </article>
}